<!DOCTYPE html . "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
	<title></title>
	<!--载入编辑器-->
	<script type="text/javascript" charset="utf-8" src="<?php echo __PUBLIC__?>/Admin/ueditor1_4_3/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="<?php echo __PUBLIC__?>/Admin/ueditor1_4_3/ueditor.all.min.js"> </script>
    <script type="text/javascript" charset="utf-8" src="<?php echo __PUBLIC__?>/Admin/ueditor1_4_3/lang/zh-cn/zh-cn.js"></script>
	<!--载入uploadify相关文件-->
	<script type="text/javascript" src="<?php echo __PUBLIC__?>/Admin/uploadify/jquery-1.8.2.min.js"></script>
	<script type="text/javascript" src="<?php echo __PUBLIC__?>/Admin/uploadify/jquery.uploadify.min.js"></script>
	<link href="<?php echo __PUBLIC__?>/Admin/uploadify/uploadify.css" type="text/css" rel="stylesheet"></link>
	<!--载入hdjs-->
	<link rel="stylesheet" type="text/css" href="<?php echo __PUBLIC__?>/Admin/hdjs/hdjs.css"/>
    <script src="<?php echo __PUBLIC__?>/Admin/hdjs/hdjs.min.js" type="text/javascript" charset="utf-8"></script>
    <style type="text/css">
		li{
			list-style: none;
			float: right;
		}
		tr{
			height: 30px;
		}
		input{
			height: 20px;
			font-size: 14px;
		}
	</style>
</head>
<body>
	
	<div class="container-fluid">
	<div class="row-fluid">
	<div class="span12">
	<form action="" method='post' enctype="multipart/form-data" id="add_goods">			
			<h2 class="hd-title-header">添加商品</h2>
			<table class='hd-table hd-table-form' style="border-top:1px solid #E5E5E5 ;">	
			<p class="hd-title-header">基本信息</p>			
			<script type="text/javascript">
				$(function(){
					$("select[name=g_cid]").change(function(){
						//抓取被选中的类型id
						var type_id = $(":selected").attr("type_id");
						$("#g_tid").val(type_id);
						$.ajax({
							type:"post",
							url:"<?php echo U('ajaxGetAttr')?>",
							data:{type_id:type_id},
							dataType:"json",
							success:function(data){
								//属性
								var attr= "";
								//规格
								var spec="";
						$.each(data, function(k,v) {
                        if(v.class==0){
                  attr += '<tr><td>'+v.ta_name+'</td><td><select name="attr['+v.ta_id+']"><option value="0"  type_id="0">请选择</option>';	
                  $.each(v.ta_value, function(kk,vv) {
                  	attr += '<option value="'+vv+'">'+vv+'</option>';
                  });
                  attr += '</select></td></tr>';
                   }else{
                   	spec += '<tr><td>'+v.ta_name+'</td><td><select name="spec['+v.ta_id+'][color][]"><option value="0" type_id="0">请选择</option>';
					 $.each(v.ta_value, function(kk,vv) {
                  	spec += '<option value="'+vv+'">'+vv+'</option>';
                  });
                   spec += '</select></td><td>附加价格:<input type="text" name="spec['+v.ta_id+'][added][]" id="" value="" /></td>';
                   spec += '<td><a href="javascript:;" class="hd-btn hd-btn-success hd-btn-sm add-spec">添加</a></td></tr>';
						}
               		  });
          			  $("#attr").html(attr);$("#spec").html(spec);
                   }
				});
			})
		})
</script>
<!--点击规格的添加按钮，复制一个-->
<script type="text/javascript">
	$(".add-spec").live("click",function(){
		var tr = $(this).parents("tr").clone();
		$(this).parents("tr").after(tr);
		tr.find(".add-spec").remove();
		var del = '<a href="javascript:;" class="hd-btn hd-btn-danger hd-btn-sm del-spec">删除</a>';
		tr.find("td").last().append(del);
	})
</script>
<!--点击规格的删除按钮，删除一个-->
<script type="text/javascript">
	$(".del-spec").live("click",function(){
		$(this).parents("tr").remove();
	})	
</script>
				<tbody>
					<tr class="info">
						<td>所属分类</td>
						<td>
							<select name="g_cid">
								
<?php foreach ($cateData as $k=>$v){?>
									<option value="<?php echo $v['cate_id']?>"  type_id="<?php echo $v['cate_type_id']?>"<?php if($olddata['g_cid']==$v['cate_id']){?>
                 selected 
               <?php }?>><?php echo $v['_cate_name']?></option>					
<?php }?>
							</select>
						</td>
					</tr>
					<tr class="info">
						<td>所属品牌</td>
						<td>
							<select name="g_bid">
								
<?php foreach ($brandData as $key=>$value){?>
		<option value="<?php echo $value['b_id']?>" <?php if($olddata['g_bid']==$value['b_id']){?>
                 selected 
               <?php }?> ><?php echo $value['b_name']?></option>
<?php }?>

						</td>
					</tr>
					<tr class="info">
						<td>商品名称</td>
						<td>
							<input type="text" name='g_name' style="width: 400px;"value="<?php echo $olddata['g_name']?>"/>
						</td>
					</tr>
					<tr class="info">
						<td>商品描述</td>
						<td>
							<input type="text" name='g_des' style="width: 400px;"/>
						</td>
					</tr>
					<tr class="info">
						<td>商品特点</td>
						<td>
							<input type="text" name='g_ted' style="width: 400px;"/>
						</td>
					</tr>
					<tr class="info">
						<td>商品货号</td>
						<td>
							<input type="text" name='g_number' value="<?php echo $olddata['g_number']?>"/>
						</td>
					</tr>
					<tr class="info">
						<td>单位</td>
						<td>
							<input type="text" name='g_unit' value="<?php echo $olddata['g_unit']?>"/>
						</td>
					</tr>
					<tr class="info">
						<td>市价场</td>
						<td>
							<input type="text" name='g_marketprice' value="<?php echo $olddata['g_marketprice']?>"/>
						</td>
					</tr>
					<tr class="info">
						<td>商城价</td>
						<td>
							<input type="text" name='g_shopprice' value="<?php echo $olddata['g_shopprice']?>"/>
						</td>
					</tr>
					<tr class="info">
						<td>点击次数</td>
						<td>
							<input type="text" name='g_click' value="<?php echo $olddata['g_click']?>"/>
						</td>
					</tr>
					<tr class="info">
						<td>库存</td>
						<td>
							<input type="text" name='g_stock'  value="<?php echo $olddata['g_stock']?>"/>
						</td>
					</tr>
				</tbody>
			</table>

			<p class="hd-title-header">商品属性</p>
			<table class="hd-table hd-table-form" id='attr' style="border-top:1px solid #E5E5E5 ;">
<?php foreach ($goodAttrData as $k1=>$v1){?>
<tr>
	
	<td><?php echo $v1['ta_name']?></td><td><select name="attr[<?php echo $v1['ta_type_id']?>]">
		<?php foreach ($v1['ta_value'] as $kk1=>$vv1){?>
		
		<option value="<?php echo $vv1?>" <?php if($v1['ga_value']==$vv1){?>
                selected
               <?php }?>><?php echo $vv1?></option>
		
		<?php }?>
	</select></td>
</tr>
<?php }?>
			</table>
			<p class="hd-title-header">商品规格</p>
			<table class="hd-table hd-table-form" id='spec' style="border-top:1px solid #E5E5E5 ;">
				<?php foreach ($goodSpecData as $k2=>$v2){?>
<tr>
	<td><?php echo $v2['ta_name']?></td><td><select name="spec[<?php echo $v1['ta_type_id']?>][color][]">
		
		<?php foreach ($v2['ta_value'] as $kk2=>$vv2){?>
		<option value="<?php echo $vv2?>" <?php if($v2['ga_value']==$vv2){?>
                selected
               <?php }?>><?php echo $vv2?></option>
		<?php }?>
	</select></td><td><input type="text" name="spec[<?php echo $v1['ta_type_id']?>][added][]"    value="<?php echo $v2['ga_addprice']?>" /></td><td><a href="javascript:;" class="hd-btn hd-btn-success hd-btn-sm add-spec">添加</a></td>
</tr>
<?php }?>
			</table>
			<?php foreach ($detaildata as $k=>$v){?>
			<p class="hd-title-header">列表图</p>
			<table class='hd-table hd-table-form' style="border-top:1px solid #E5E5E5 ;">
				<script type="text/javascript">
					$(function(){
					 $(".del-image").live("click",function(){
					    var li = $(this).parents("li");
					    var path = li.attr("path");
					   $.ajax({
					 		type:"post",
					 		url:"<?php echo U('delImg')?>",
					 		data:{path:path},
					 		success:function(data){
					 			if(data==1){
					 				li.remove();
					 			}
					 		}
					 	});
					  })
					})
				</script>
<!--编辑时点击关闭土坯阿尼出图片-->
	<script type="text/javascript">
					$(function(){
					 $(".dele-image").live("click",function(){
					 	var li = $(this).parents("li");
					      li.remove();
					 });
					 })
				</script>				
				<tr class="info">
					<td>上传图片</td>
					<td>
						<input id="file1" type="file" multiple="true" name="photos"/>
	            		 <span>类型: *.jpg,*.png 大小: 2000KB 数量: 10</span>
			             <script type="text/javascript">
			                $(function() {
			                    $('#file1').uploadify({
			                        'formData'     : {//POST数据
			                            '<?php echo session_name();?>' : '<?php echo session_id();?>',
			                        },
			                        'fileTypeDesc' : '上传文件',//上传描述
			                        'fileTypeExts' : '*.jpg;*.png',
			                        'swf'      : '<?php echo __PUBLIC__?>/Admin/uploadify/uploadify.swf',
			                        'uploader' : "<?php echo U('ajaxUpload')?>",
			                        'buttonText':'选择文件',
			                        'fileSizeLimit' : '2000KB',
			                        'uploadLimit' : 1000,//上传文件数
			                        'width':65,
			                        'height':25,
			                        'successTimeout':10,//等待服务器响应时间
			                        'removeTimeout' : 0.2,//成功显示时间
			                        'onUploadSuccess' : function(file, data, response) {
//			       	 console.log(data);
//			         data=$.parseJSON(data);
			                        var imageUrl = data?data:'<?php echo __PUBLIC__?>/image/default.png';
			                            var li="<li path='"+data+"' url='"+data+"'><img src='"+imageUrl+"' class='hd-w80 hd-h70'/><a href='javascript:;' style='color:red' class='del-image'>X</a>";
			                            li +='<input type="hidden" name="g_pic" value="'+data+'"/>';
			                            li +='</li>';
			                            $("#photo-list").prepend(li);
			                        }
			                    });
			                });
			             </script>
					</td>
					<td id='photo-list'>
						<li ><img src="<?php echo $olddata['g_pic']?>"  class='hd-w80 hd-h70' alt="" /><a href='javascript:;' style='color:red' class='dele-image'>X</a><input type="hidden" name="g_pic" value="<?php echo $olddata['g_pic']?>"/></li>
					</td>	
				</tr>
			</table>
			<p class="hd-title-header">商品图册</p>
			<table class='hd-table hd-table-form' style="border-top:1px solid #E5E5E5 ;">
			<tr class="info">
					<td>上传图片</td>
					<td>
						<input id="file2" type="file" multiple="true" name="photos"/>
	            		 <span>类型: *.jpg,*.png 大小: 2000KB 数量: 10</span>
			             <script type="text/javascript">
			                $(function() {
			                    $('#file2').uploadify({
			                        'formData'     : {//POST数据
			                            '<?php echo session_name();?>' : '<?php echo session_id();?>',
			                        },
			                        'fileTypeDesc' : '上传文件',//上传描述
			                        'fileTypeExts' : '*.jpg;*.png',
			                        'swf'      : '<?php echo __PUBLIC__?>/Admin/uploadify/uploadify.swf',
			                        'uploader' : "<?php echo U('ajaxUploadImg')?>",
			                        'buttonText':'选择文件',
			                        'fileSizeLimit' : '2000KB',
			                        'uploadLimit' : 1000,//上传文件数
			                        'width':65,
			                        'height':25,
			                        'successTimeout':10,//等待服务器响应时间
			                        'removeTimeout' : 0.2,//成功显示时间
			                        'onUploadSuccess' : function(file, data, response) {
//			       	 console.log(data);
//			         data=$.parseJSON(data);
//			         alert(data.small);
			                        var imageUrl = data?data:'<?php echo __PUBLIC__?>/image/default.png';
			                            var li="<li path='"+data+"' url='"+data+"'><img src='"+imageUrl+"' class='hd-w80 hd-h70'/><a href='javascript:;' style='color:red' class='del-image'>X</a>";
			                            li +='<input type="hidden" name="photos[]" value="'+data+'"/>';
			                            li +='</li>';
			                            $("#photo-list1").prepend(li);
			                        }
			                    });
			                });
			             </script>
					</td>
					<td id='photo-list1'>
	<?php foreach ($v['gd_small'] as $kk=>$vv){?>
	  <?php if(!empty($vv)){?>
                
				<li><img src="<?php echo $vv?>"  class='hd-w80 hd-h70' alt="" /><a href='javascript:;' style='color:red' class='dele-image'>X</a><input type="hidden" name="photos[]" value="<?php echo $vv?>"/></li>
				
               <?php }?>	
			<?php }?>			
					</td>
					
				</tr>
			</table>
			<p class="hd-title-header" id="detail">商品详细</p>
			<table class='hd-table hd-table-form'>
				<tr class="hide info">
					<td>
						<script id="ed" type="text/plain" style="width:100%;height:300px;" name="gd_info"><?php echo $v['gd_info']?></script>
	                    <script>
							var ue = UE.getEditor('ed');
						</script>
					</td>
				</tr>
			</table>
			<p class="hd-title-header" id="service">售后服务</p>
			<table class='table'>
				<tr class="hide info">
					<td>
<!--<textarea name="gd_service" id="service" ></textarea>-->
				<script id="ed1" type="text/plain" style="width:100%;height:300px;" name="gd_service"><?php echo $v['gd_service']?></script>
	                    <script>
							var ue = UE.getEditor('ed1');
						</script>
					</td>
				</tr>
				</table>
			<?php }?>
<input type="hidden" name="g_tid" id="g_tid" value="<?php echo $olddata['g_tid']?>" />
			<input type="hidden"name="g_id" value="<?php echo $olddata['g_id']?>" />
			<input type="submit" value="确认编辑" class="hd-btn hd-btn-success" style="height: 40px;"/>
	</form>

	</div>
	</div>
	</div>
</body>
</html>